package com.nanxun.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nanxun.domain.Category;
import com.nanxun.domain.Prod;
import com.nanxun.model.Result;
import com.nanxun.service.SearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *
 * 搜索业务控制层
 * @param
 * @return
 * @author nanxun
 * @create 2025/6/23
 **/

@Api(tags = "搜索业务接口管理")
@RestController
public class SearchController {

    @Resource
    private SearchService searchService;


    /**
     *
     * 根据分组标签分页查询商品
     * @param current 页码
     * @param size 每页显示条数
     * @param tagId 分组标签id
     * @return com.nanxun.model.Result<com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.nanxun.domain.Prod>>
     * @author nanxun
     * @create 2025/6/23
     **/

    // prod/prodListByTagId?tagId=6&size=6
    @ApiOperation("根据分组标签分页查询商品")
    @GetMapping("prod/prodListByTagId")
    public Result<Page<Prod>> loadWxProdPageByTagId(@RequestParam(defaultValue = "1") Long current,
                                                    @RequestParam Long size,
                                                    @RequestParam Long tagId
                                                    ){
        //根据分组标签分页查询商品
        Page<Prod> page=searchService.queryWxProdPageByTagId(current,size,tagId);
        return Result.success(page);
    }

    /**
     *
     *根据商品类目标识查询商品集合
     * @param categoryId 商品类目id
     * @return com.nanxun.model.Result<java.util.List<com.nanxun.domain.Prod>>
     * @author nanxun
     * @create 2025/6/24
     **/
    // prod/category/prod/list?categoryId=107
    @ApiOperation("根据商品类目标识查询商品集合")
    @GetMapping("prod/category/prod/list")
    public Result<List<Prod>> loadProdListByCategoryId(@RequestParam Long categoryId){
        //根据商品类目标识查询商品集合
        List<Prod> list = searchService.queryWxProdListByCategoryId(categoryId);
        return Result.success(list);
    }

}
